<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<button @click="changePage()">跳转2.5.2</button>
			<button @click="changePage1()">跳转2.6.0</button>
			<button @click="login()">登录</button>
			<button @click="joinGroup()">加群</button>
			<button @click="searchGroup()">搜索群组列表</button>
		</view>
		<view class="text-area">
			<button @click="quietLogin()">退群</button>
		</view>
	</view>
</template>

<script>
	import TIM from './tim-wx2.4.2.js'
	let options ={
	    SDKAppID: 1400282329
	};
	let tim = TIM.create(options);
	tim.setLogLevel(4);
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			changePage(){
				uni.redirectTo({
					url:'./index2.5.2'
				});
			},
			changePage1(){
				uni.redirectTo({
					url:'./index2.6.0'
				});
			},
			login(){
				let promise = tim.login({userID: '1217763759586545664', userSig: 'eJw1jksLgkAUhf-LrMOcx50ZhTY9FkVJYoG4E53kFsWgg1jRf2-QWp7HdzhvctpngRkstobEWoownI1Wb1oSExaEZNJdfSutxZrE1HeYZpxFU4K1eTi84AhQRpWSXEEEWoIAKcV-ABufq6F6VvNjKfTWJrzIXYkN5pQn3frabM5pvypU9loednm6*IEO7-4aBQ0AQkTw*QLLHTK2'});
				promise.then(function(imResponse) {
					console.log("登录成功", imResponse.data) // 登录成功
				  if (imResponse.data.repeatLogin === true) {
				    // 标识账号已登录，本次登录操作为重复登录。v2.5.1 起支持
				    console.log(imResponse.data.errorInfo)
				  }
				}).catch(function(imError) {
				  console.warn('login error:', imError); // 登录失败的相关信息
				});
			},
			joinGroup(){
				let promise = tim.joinGroup({ groupID: 'live1242716761845927936num0', type: TIM.TYPES.GRP_CHATROOM });
				promise.then(function(imResponse) {
					console.log("加群成功",imResponse)
				  switch (imResponse.data.status) {
				    case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
				      break;
				    case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
				      console.log(imResponse.data.group); // 加入的群组资料
				      break;
				    case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
				      break;
				    default:
				      break;
				  }
				}).catch(function(imError){
				  console.warn('joinGroup error:', imError); // 申请加群失败的相关信息
				});
			},
			searchGroup(){
				let promise = tim.getGroupList();
				promise.then(function(imResponse) {
					console.log("搜索群组列表成功",imResponse)
				  console.log(imResponse.data.groupList); // 群组列表
				}).catch(function(imError) {
				  console.warn('getGroupList error:', imError); // 获取群组列表失败的相关信息
				});
			},
			quietLogin(){
				let promise = tim.quitGroup('live1242716761845927936num0');
				promise.then(function(imResponse) {
					console.log("退群成功",imResponse)
				  console.log(imResponse.data.groupID); // 退出成功的群 ID
				}).catch(function(imError){
				  console.warn('quitGroup error:', imError); // 退出群组失败的相关信息
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
